import {createSlice,configureStore} from '@reduxjs/toolkit'
import {persistReducer} from 'redux-persist'
import storageSession from 'redux-persist/lib/storage/session'
import thunk from 'redux-thunk'

// 帮你创建一个切片
const userStore = createSlice({
    name:'userStore', //  模块的名字
    initialState:{
        userInfo:{} as any,
        doctorInfo:{} as any,
    }, 
    reducers:{
        // add(state,action){
        //     // 因为引入immer, 所以你可以直接修改仓库中的数据
        //     // action : type , payload
        //     state.userInfo.push(action.payload)
        // },
        setUserInfo(state,action){
            const {payload} = action;
            state.userInfo = payload
        },
        setDoctorInfo(state,action){
            const {payload} = action;
            state.doctorInfo = payload
        }
    }
})
export const userAction = userStore.actions; 
// 导出的目的是为了在页面中使用的时候， 给哪个模块的发什么指令
const userReducer = userStore.reducer


let storeConfig = {
    key:'userstore',
    storage:storageSession,
    blacklist:[]  
}
const store = configureStore({
    reducer:{
        task:persistReducer(storeConfig,userReducer)

    },
    devTools:true,
    middleware:[thunk]
})
export default store;